
window.console = window.console || {};
window.console._log = window.console._log || [];
window.console.show = function () {
  var messages = window.console._log;
  for (var i = 0, n = messages ? messages.length : 0; i < n; i++) {
    console.log(messages[i]);
  }
}

window.ASC = window.ASC || {};
window.ASC.Controls = window.ASC.Controls || {};
window.ASC.Resources = window.ASC.Resources || {};

window.ASC.Controls.cookies = (function () {
  var get = function (name) {
    if (typeof name === 'undefined') {
      return '';
    }
    var
      start = 0,
      end = 0,
      value = '',
      search = ' ' + name + '=',
      cookie = ' ' + document.cookie;

	  if ((start = cookie.indexOf(search)) !== -1) {
	    start += search.length;
		  if ((end = cookie.indexOf(";", start)) === -1) {
  			end = cookie.length;
	  	}
		  value = cookie.substring(start, end);
	  }
    return decodeURI(value);
  };

  var set = function (name, value, expires, path, domain, secure) {
    if (typeof name === 'undefined' || typeof value === 'undefined') {
      return undefined;
    }
    expires = expires || 365;
    if (isFinite(+expires)) {
      var currentDate = new Date();
      currentDate.setTime(currentDate.getTime() + expires * 8640000);
      expires = currentDate.toUTCString();
    }
    expires = expires ? ';expires=' + expires : '';
    path    = path    ? ';path='    + path    : ';path=/';
    domain  = domain  ? ';domain='  + domain  : '';
    secure  = secure  ? ';secure='  + secure  : '';
    document.cookie = name + '=' + encodeURI(value) + expires + path + domain + secure;
    return value;
  };

  var remove = function (name, path, domain) {
    if (name && document.cookie.indexOf(name + '=')  != -1) {
      path    = path    ? ';path='    + path    : ';path=/';
      domain  = domain  ? ';domain='  + domain  : '';
      document.cookie = name + '=' + path + domain + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    }
    return true;
  };

  return {
    get     : get,
    set     : set,
    remove  : remove
  };
})();

